// Fill out your copyright notice in the Description page of Project Settings.


#include "StateMachine/PlayerState/GroundState.h"

#include "Core/Character2D.h"
#include "StateMachine/StateMachine.h"
#include "StateMachine/PlayerState/DashState.h"
#include "StateMachine/PlayerState/JumpState.h"
#include "StateMachine/PlayerState/FallState.h"
#include "GameFramework/CharacterMovementComponent.h"

void UGroundState::Init(APlayerController* Controller, ACharacter2D* Player, UStateMachine* SM)
{
	Super::Init(Controller, Player, SM);
	MovementComponent = Character->GetCharacterMovement();
}

void UGroundState::Enter()
{
	Super::Enter();
	
}

void UGroundState::Tick(float Delta)
{
	Super::Tick(Delta);
	
	const FVector Velocity = Character->GetVelocity();
	if (MovementComponent->IsFalling() && Velocity.Z < -0.1f)
	{
		StateMachine->SwitchState(UFallState::StaticClass());
	}
}

void UGroundState::InputSignal(EInputSignal Signal, const FInputActionValue& Value)
{
	Super::InputSignal(Signal, Value);
	
	if (Signal == EInputSignal::Dash)
	{
		StateMachine->SwitchState(UDashState::StaticClass());
		return;
	}

	if (Signal == EInputSignal::Jump)
	{
		StateMachine->SwitchState(UJumpState::StaticClass());
		return;
	}
}
